home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / ANTENNA / YAGIU112 / RANDOMIS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-25  |  3.4 KB  |  120 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <errno.h>
  4. #ifdef sun
  5. #include <stdlib.h>
  6. #endif
  7. #include "yagi.h"
  8.  
  9. extern double boom_factor;
  10. extern int errno;
  11. #define MIN_RDS   0.05 /* Minimum reflector-driven spacing in lambda */
  12.  
  13. void randomise(int randomisation_method, double frequency, double max_percent, double **driven_data, double**parasitic_data, int driven, int parasites)
  14. {
  15.     int i,elements;
  16.     static int run_first_time=0;
  17.     double y, old_boom_length, new_boom_length, a,b,lambda,**z,l,x,taper;
  18.     static double max_boom_length;
  19.     lambda=300/frequency;
  20.     if(run_first_time==0)
  21.     {
  22.         max_boom_length=(1+boom_factor/100)*parasitic_data[parasites][X];
  23.     }
  24.     run_first_time++;
  25.     if ((randomisation_method & DRIVEN_LENGTH) == DRIVEN_LENGTH) /* 1 */
  26.     {
  27.         for(i=1;i<=driven; ++i) /* randomise the driven */
  28.         {
  29.             y=1+0.02*max_percent*(randreal()-0.5);
  30.             driven_data[i][LENGTH]*=y;
  31.         }
  32.     }
  33.     if ((randomisation_method & DRIVEN_POSITION) == DRIVEN_POSITION) /* 2 */
  34.     {
  35.         for(i=1;i<=driven; ++i) /* randomise the driven position */
  36.         {
  37.             y=1+0.02*max_percent*(randreal()-0.5);
  38.             driven_data[i][X]*=y;
  39.         }
  40.     }
  41.     if ((randomisation_method & REFLECTOR_LENGTH) == REFLECTOR_LENGTH) /* 4 */
  42.     {
  43.  
  44.        /* reflector position stays at x=0 */
  45.         y=1+0.02*max_percent*(randreal()-0.5);
  46.         parasitic_data[1][LENGTH]*=y;
  47.     }
  48.  
  49.     if ((randomisation_method & DIRECTOR_LENGTH) == DIRECTOR_LENGTH) /* 8 */
  50.     {
  51.         for(i=2; i<=parasites; ++i)
  52.         {
  53.             y=1+0.02*max_percent*(randreal()-0.5);
  54.             parasitic_data[i][LENGTH]*=y;
  55.             /* make sure directors dont get longer down the boom */
  56.             if((parasitic_data[i][LENGTH]>parasitic_data[i-1][LENGTH]) && (i>2))
  57.                 parasitic_data[i][LENGTH]=parasitic_data[i-1][LENGTH]; 
  58.         }
  59.     }
  60.  
  61.     if ((randomisation_method & DIRECTOR_POSITION) == DIRECTOR_POSITION) /* 16 */
  62.     {
  63.         old_boom_length=parasitic_data[parasites][X];    
  64.         y=1+0.02*max_percent*(randreal()-0.5);
  65.         new_boom_length=old_boom_length*y;
  66.         if(new_boom_length > max_boom_length)
  67.             new_boom_length=max_boom_length;
  68.         /* rearrange directors */
  69.         for(i=2; i<=parasites; ++i)
  70.         {
  71.             y=1+0.02*max_percent*(randreal()-0.5);
  72.             parasitic_data[i][X]*=y*(new_boom_length/old_boom_length);
  73.         }
  74.     }
  75.     if ((randomisation_method & ALL_ELEMENT_LENGTHS_IDENTICAL)==ALL_ELEMENT_LENGTHS_IDENTICAL) /* 32 */
  76.     {
  77.             y=1+0.02*max_percent*(randreal()-0.5);
  78.             for(i=1; i<=driven; ++i)
  79.                 driven_data[i][LENGTH]*=y;
  80.             for(i=1; i<=parasites; ++i)
  81.                 parasitic_data[i][LENGTH]=driven_data[1][LENGTH];
  82.     }
  83.     if ((randomisation_method & LINEAR_TAPER)==LINEAR_TAPER) /* 64 */
  84.     {
  85.         a=1+(0.1*randreal()); /* 1.00 to 1.1 */
  86.         taper=(a-1)/driven_data[1][X];
  87.         parasitic_data[1][LENGTH]=a*driven_data[1][3]; /* reflector = a*driven */
  88.         for(i=2; i<=parasites; ++i)
  89.                 parasitic_data[i][LENGTH]=parasitic_data[1][3]-taper*(parasitic_data[i][X]-driven_data[1][X]);
  90.     }
  91.  
  92.     if ((randomisation_method & RESONATE_DRIVEN)==RESONATE_DRIVEN) /* 128 */
  93.     {
  94.         if(run_first_time==1)
  95.         {
  96.             elements=driven+parasites;
  97.             z=dmatrix(1L,(long)elements,2L,2L*(long)elements);
  98.             l=0.44*lambda;
  99.             do
  100.             {
  101.                 driven_data[1][LENGTH]=l;            
  102.                 self_impedance(1, frequency*1e6,driven,parasites,driven_data,z);
  103.                 l+=0.00005*lambda;
  104.                 driven_data[1][LENGTH]=l;            
  105.                 x=z[1][2];
  106.             }while(z[1][2]<0.0);
  107.             printf("Driven element set to :l=%lf m = %lf wavlengths\n",l,l/lambda);
  108.             free_dmatrix(z,1L,elements,1L,2L*elements);
  109.         }
  110.     }
  111. #ifdef DEBUG
  112.     if(errno)
  113.     {
  114.     fprintf(stderr,"Errno =%d in randomis.c\n", errno);
  115.     exit(1);
  116.     }
  117. #endif
  118. }
  119.  
  120.